package com.ruoyi.web.controller.share;

import java.util.List;

import com.ruoyi.share.domain.ShareGoodsRemarks;
import com.ruoyi.share.domain.ShareGoodsRemarksFixed;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.share.domain.ShareGoods;
import com.ruoyi.share.service.IShareGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品信息Controller
 *
 * @author ruoyi
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/api/shoregoods")
public class ShareGoodsController extends BaseController
{
    @Autowired
    private IShareGoodsService shareGoodsService;

    /**
     * 分页查询商品列表
     * @param shareGoods 商品信息
     * @param pageNum 当前页码
     * @param pageSize 查询条数
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ShareGoods shareGoods, @RequestParam Integer pageNum, @RequestParam Integer pageSize)
    {
        List<ShareGoods> list = shareGoodsService.selectShareGoodsListPage(shareGoods,pageNum,pageSize);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @GetMapping("/export")
    public AjaxResult export(ShareGoods shareGoods)
    {
        List<ShareGoods> list = shareGoodsService.selectShareGoodsList(shareGoods);
        ExcelUtil<ShareGoods> util = new ExcelUtil<ShareGoods>(ShareGoods.class);
        return util.exportExcel(list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @GetMapping(value = "getGoods/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(shareGoodsService.selectShareGoodsByGoodsId(goodsId));
    }

    /**
     * 新增商品信息
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ShareGoods shareGoods)
    {
        int i = shareGoodsService.insertShareGoods(shareGoods);
        return toAjax(i);
    }

    /**
     * 修改商品信息
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ShareGoods shareGoods)
    {
        return toAjax(shareGoodsService.updateShareGoods(shareGoods));
    }

    /**
     * 删除商品信息
     */
	@DeleteMapping("/remove/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(shareGoodsService.deleteShareGoodsByGoodsIds(goodsIds));
    }

    @PutMapping("/updateGoodsPutawayStatus")
    public AjaxResult updateGoodsPutawayStatus( @RequestBody  ShareGoods shareGoods){
        System.err.println(shareGoods.getPutawayStatus()+":"+shareGoods.getGoodsId());
	    return toAjax(shareGoodsService.updateShareGoodsPutawayStatusByGoodsId(shareGoods.getPutawayStatus(),shareGoods.getGoodsId()));
    }

}
